<template>
	<ul class="list">
		<li class="item" v-for="item of letters" :key="item" :ref="item"
		@click="handleletterClick" 
		@touchstart="handelTouchStart" 
		@touchmove="handelTouchMove"
		@touchend="handelTouchEnd"
		>{{item}}</li>
	</ul>
</template>

<script>
	export default {
		name: 'cityAlphabet',
		data() {
			return {
				touchStatus: false,
				startY : 0,
				timer : ""
			};
		},
		props:{
			cities:Object
		},
		updated (){
			this.startY =  this.$refs['A'][0].offsetTop
		},
		computed: {
			letters() {
				const letters = []
				for(let i in this.cities){
					letters.push(i)
				}
				return letters
				console.log(letters)
			}
		},
		methods: {
			handleletterClick(e) {				this.$emit('change',e.target.innerText)
				console.log(e.target.innerText);
			},
			handelTouchStart(e){
				this.touchStatus = true
			},
			handelTouchMove(e){
				if(this.touchStatus){
					const touchY = e.touches[0].clientY - 79
					const index = (Math.floor(( touchY - this.startY ) / 20))
					if(index >= 0 && index < this.letters.length)
					this.$emit('change',this.letters[index])
				}
			},
			handelTouchEnd(e){
				this.touchStatus = false
			}
		},
	}
</script>

<style scoped lang="stylus">
	@import '~styles/varibles.styl'
	.list
	 display: flex
	 flex-direction: column
	 justify-content: center
	 position:absolute
	 right:0
	 width:.4rem
	 top:1.58rem
	 bottom:0
	 .item
	  text-align:center
	  line-height:.4rem
	  color: $bgColor
</style>
